package com.stp.kafka.config.registry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.stereotype.Component;

/**
 * 第一种控制 监听器是否启动
 */
//@Component
public class KafkaListenerRegistryComponent {

    @Autowired
    private ConsumerFactory consumerFactory;

    @Bean
    public ConcurrentKafkaListenerContainerFactory delayContainerFactory() {
        ConcurrentKafkaListenerContainerFactory container = new ConcurrentKafkaListenerContainerFactory();
        //container.setConsumerFactory(consumerFactory);
        //禁止KafkaListener自启动
        //container.setAutoStartup(false);
        container.setAutoStartup(true);
        return container;
    }
}
